﻿using Kingdee.BOS.App.Data;
using Kingdee.BOS.BusinessEntity.YunZhiJia;
using Kingdee.BOS.Core.DynamicForm;
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.ServiceHelper;
using Kingdee.BOS.Util;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.IO;
using System.Linq;
using System.Net;
using System.Runtime.ConstrainedExecution;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using static LiMinCRMPlugin.InterfaceDocking.ReceivableMode;

namespace LiMinCRMPlugin.InterfaceDocking
{
    /// <summary>
    /// 应收单审核插件
    /// </summary>
    /// <remarks>
    /// 功能：应收单在创建审核后自动传到CRM。
    /// 创建人：mey
    /// 创建日期：2024.3.26
    /// 修改信息（1）：修改人，修改日期，修改内容
    /// </remarks>
    /// 
    [Description("应收单审核同步至CRM")]
    [HotUpdate]
    public class ReceivableToCRM : AbstractOperationServicePlugIn
    {
        //OnPreparePropertys 数据加载前，确保需要的属性被加载
        public override void OnPreparePropertys(PreparePropertysEventArgs e)
        {
            base.OnPreparePropertys(e);
            //编码
            e.FieldKeys.Add("FBillNo");
            //是否淡储
            e.FieldKeys.Add("F_DEV_Survive");
            //CRM编码
            e.FieldKeys.Add("F_DEV_CRMNumber");
            //订单编号
            e.FieldKeys.Add("F_DEV_OrderNo");
            //销售部门
            e.FieldKeys.Add("FSALEDEPTID");
            //销售员
            e.FieldKeys.Add("F_DEV_Saler");
            //销售组织
            e.FieldKeys.Add("FSALEORGID");
            //日期
            e.FieldKeys.Add("FDATE");
            //结算组织
            e.FieldKeys.Add("FSETTLEORGID");
            //交货地点
            e.FieldKeys.Add("F_RDLV_HeadLocationId");
            //是否调货订单
            e.FieldKeys.Add("F_RDLV_Seasoning_w5c");
            //备注
            e.FieldKeys.Add("FAR_Remark");
            //结算币别
            e.FieldKeys.Add("FCURRENCYID");
            //是否定制
            e.FieldKeys.Add("F_DEV_Offset");
            //交货方式
            e.FieldKeys.Add("F_RDLV_HeadDeliveryWay");
            //客户名称
            e.FieldKeys.Add("FCUSTOMERID");
            //收款条件
            e.FieldKeys.Add("FPayConditon");
            //结算方式
            e.FieldKeys.Add("FSettleTypeID");

            //仓管员
            e.FieldKeys.Add("F_RDLV_StockerID_dvn");
            //承运商
            e.FieldKeys.Add("F_RDLV_CarrierID");
            //运输单号
            e.FieldKeys.Add("F_RDLV_CarriageNO");
            //仓库
            e.FieldKeys.Add("F_RDLV_Stock");
            //源单标识
            e.FieldKeys.Add("FSOURCEBILLTYPEID");
            //源单编码
            e.FieldKeys.Add("FSourceBillNo");
            //产品名称
            e.FieldKeys.Add("FMATERIALID");
            //含税单价
            e.FieldKeys.Add("FTaxPrice");
            //是否赠品
            e.FieldKeys.Add("FIsFree");
            //税率(%)  
            e.FieldKeys.Add("FEntryTaxRate");
            //销售数量
            e.FieldKeys.Add("FPriceQty");
            //批次号  
            e.FieldKeys.Add("FLot");
            //销售单位
            e.FieldKeys.Add("FPRICEUNITID");
            //计价单位  
            e.FieldKeys.Add("FPRICEUNITID");
            //库存组织 
            e.FieldKeys.Add("FSTOCKORGID");

            //价税合计  
            e.FieldKeys.Add("FALLAMOUNTFOR");


            //同步CRM状态
            e.FieldKeys.Add("F_DEV_FSTATUS");
            //立账类型
            e.FieldKeys.Add("FSetAccountType");
            //转销
            e.FieldKeys.Add("FIsWriteOff");
            //转销
            e.FieldKeys.Add("FCreatorId");

        }
        /// <summary>
        /// 事务结束后事件
        /// </summary>
        /// <param name="e"></param>
        public override void AfterExecuteOperationTransaction(AfterExecuteOperationTransaction e)
        {
            base.AfterExecuteOperationTransaction(e);

            //读取全部的单据,for循环,转换成DynamicObject类型
            foreach (DynamicObject entity in e.DataEntitys)
            {
                string FSetAccountType = Convert.ToString(entity["FSetAccountType"]);//立账类型                 
                bool FIsWriteOff = Convert.ToBoolean(entity["IsWriteOff"]);//转销              
                if (FSetAccountType == "3" && FIsWriteOff == true)//只有转销的财务应收才传送
                {


                    DataTable dt = APISetting();
                    string httpUrl = dt.Rows[0]["F_RDLV_URL"].ToString();
                    string httpSystemId = dt.Rows[0]["F_RDLV_SystemId"].ToString();
                    string httpPassword = dt.Rows[0]["F_RDLV_Password"].ToString();

                    #region  单据头信息
                    string FSTATUS = Convert.ToString(entity["F_DEV_FSTATUS"]);//同步CRM状态 空-未同步，成功-同步成功，失败-同步失败
                    string FID = Convert.ToString(entity["Id"]);//内码                      
                    string Number = entity["BillNo"].ToString();//编码


                    string UserAccount = "";//用户账号
                    DynamicObject User = entity["CreatorId"] as DynamicObject;//用户
                    if (User != null)
                    {
                        UserAccount = Convert.ToString(User["UserAccount"]);
                    }

                    string sfdc1 = entity["F_DEV_Survive"].ToString();//是否淡储 枚举：[0:否,1:是]
                    string crmbm1 = entity["F_DEV_CRMNumber"].ToString();//CRM编码
                    string ddbh1 = entity["F_DEV_OrderNo"].ToString();//订单编号


                    DynamicObject FSaledep = entity["SALEDEPTID"] as DynamicObject;//销售部门 
                    string xsbm1 = "";
                    if (FSaledep != null)
                    {
                        xsbm1 = Convert.ToString(FSaledep["Number"]);

                    }
                    DynamicObject FSaler = entity["F_DEV_Saler"] as DynamicObject;//销售员 
                    string xsy1 = "";
                    if (FSaler != null)
                    {
                        xsy1 = Convert.ToString(FSaler["Number"]);

                    }
                    DynamicObject FSALEORG = entity["SALEORGID"] as DynamicObject;//销售组织 
                    string xszz1 = "";
                    if (FSALEORG != null)
                    {
                        xszz1 = Convert.ToString(FSALEORG["Number"]);

                    }
                    string rq1 = "";
                    if (entity["DATE"] != null && entity["DATE"].ToString() != "")
                    {
                        rq1 = Convert.ToDateTime(entity["DATE"]).ToString("yyyy-MM-dd");//业务日期 ywrq
                    }

                    string fhzz1 = "";//财务应收没有发货组织

                    DynamicObject FSETTLEORG = entity["SETTLEORGID"] as DynamicObject;//结算组织 
                    string jszz1 = "";
                    if (FSETTLEORG != null)
                    {
                        jszz1 = Convert.ToString(FSETTLEORG["Number"]);

                    }

                    DynamicObject FHeadLocation = entity["F_RDLV_HeadLocationId"] as DynamicObject;//结算组织 
                    string jhdd1 = "";
                    if (FHeadLocation != null)
                    {
                        jhdd1 = Convert.ToString(FHeadLocation["Name"]);

                    }
                    string sfdhdd1 = entity["F_RDLV_Seasoning_w5c"].ToString();//是否淡储 枚举：[0:否,1:是]
                    string bz1 = entity["REMARK"].ToString();//备注

                    DynamicObject FCURRENCYID = entity["CURRENCYID"] as DynamicObject;//结算币别 
                    string jsbb1 = "";
                    if (FCURRENCYID != null)
                    {
                        jsbb1 = Convert.ToString(FCURRENCYID["Number"]);

                    }

                    string sfdz1 = entity["F_DEV_Offset"].ToString();//是否定制   枚举：[0:否,1:是]

                    DynamicObject HeadDeliveryWay = entity["F_RDLV_HeadDeliveryWay"] as DynamicObject;//交货方式  枚举：[0:发货,1:自提] 
                    string jhfs1 = "";
                    if (HeadDeliveryWay != null)
                    {
                        jhfs1 = Convert.ToString(HeadDeliveryWay["Name"]);

                        if (jhfs1 == "发货")
                            jhfs1 = "0";
                        else
                        if (jhfs1 == "自提")
                            jhfs1 = "1";
                        else
                            jhfs1 = "";
                    }

                    DynamicObject FCUSTOMERID = entity["CUSTOMERID"] as DynamicObject;//客户 
                    string khmc1 = "";
                    if (FCUSTOMERID != null)
                    {
                        khmc1 = Convert.ToString(FCUSTOMERID["Name"]);

                    }

                    DynamicObject FPayConditon = entity["PayConditon"] as DynamicObject;//收款条件 
                    string sktj1 = "";
                    if (FPayConditon != null)
                    {
                        sktj1 = Convert.ToString(FPayConditon["Number"]);

                    }


                    DynamicObject FSettleType = entity["FSettleTypeID"] as DynamicObject;//结算方式 
                    string jsfs1 = "";
                    if (FSettleType != null)
                    {
                        jsfs1 = Convert.ToString(FSettleType["Number"]);

                    }


                    DynamicObject FStocker = entity["F_RDLV_StockerID_dvn"] as DynamicObject;//仓管员 
                    string cgy1 = "";
                    if (FStocker != null)
                    {
                        cgy1 = Convert.ToString(FStocker["Id"]);

                    }
                    DynamicObject FCarrier = entity["F_RDLV_CarrierID"] as DynamicObject;//承运商 
                    string cys1 = "";
                    if (FCarrier != null)
                    {
                        cys1 = Convert.ToString(FCarrier["Number"]);

                    }
                    string ysdh1 = entity["F_RDLV_CarriageNO"].ToString();//运输单号
                    #endregion

                    List<Datadetail> datadetails = new List<Datadetail>();

                    //明细
                    DynamicObjectCollection FEntity = entity["AP_PAYABLEENTRY"] as DynamicObjectCollection;
                    
                    foreach (DynamicObject Fe in FEntity)
                    {
                        string FEntryId = Fe["ID"].ToString();//明细内码
                        string FSEQ = Fe["SEQ"].ToString();//行号

                        DynamicObject FStock = Fe["F_RDLV_Stock"] as DynamicObject;//仓库 
                        string ck1 = "";
                        if (FStock != null)
                        {
                            ck1 = Convert.ToString(FStock["Number"]);

                        }

                        string ydbs1 = "";//源单标识
                        string ydbm1 = "";//源单内码


                        DynamicObject FMATERIAL = entity["MATERIALID"] as DynamicObject;//产品名称 
                        string cp11 = "";
                        string cp1 = "";
                        if (FMATERIAL != null)
                        {
                            cp11 = Convert.ToString(FMATERIAL["Name"]);
                            cp1 = Convert.ToString(FMATERIAL["Number"]);
                        }

                        decimal hsdj1 = Convert.ToDecimal(entity["TaxPrice"]); //含税单价

                        string sfzp1 = Convert.ToBoolean(entity["IsFree"]) == true ? "1" : "0"; //是否赠品枚举：[0:否,1:是]

                        decimal sl1 = Convert.ToDecimal(entity["EntryTaxRate"]); // 税率(%)

                        decimal xssl1 = Convert.ToDecimal(entity["SalQty"]); // 销售数量

                        DynamicObject FLot = Fe["FLot"] as DynamicObject;//批次号 
                        string pch1 = "";
                        if (FLot != null)
                        {
                            pch1 = Convert.ToString(FLot["Number"]);

                        }

                        DynamicObject FPRICEUNIT = Fe["PRICEUNITID"] as DynamicObject;//销售单位 
                        string xsdw1 = "";
                        if (FPRICEUNIT != null)
                        {
                            xsdw1 = Convert.ToString(FPRICEUNIT["Number"]);

                        }
                        DynamicObject FSTOCKORG = Fe["FSTOCKORGID"] as DynamicObject;//库存组织 
                        string kczz1 = "";
                        if (FSTOCKORG != null)
                        {
                            kczz1 = Convert.ToString(FSTOCKORG["Number"]);

                        }

                        decimal jshj1 = Convert.ToDecimal(entity["FALLAMOUNTFOR"]); // 价税合计

                        Operate operate = new Operate()
                        {
                            action = "Save"
                        };
                        
                        Datadetail datadetail = new Datadetail()
                        {
                            operate = operate,
                          
                        };



                        datadetails.Add(datadetail);
                    }
                    #region 插入更新赋值
                    mainTable mainTable1 = new mainTable()
                    {
                        sfdc = sfdc1,
                        djnm = FID,
                        djbh = Number,
                        crmbm = crmbm1,
                        ddbh = ddbh1,
                        xsbm = xsbm1,
                        xsy = xsy1,
                        xszz = xszz1,
                        rq = rq1,
                        fhzz = fhzz1,
                        jszz = jszz1,
                        jhdd = jhdd1,
                        sfdhdd = sfdhdd1,
                        bz = bz1,
                        jsbb = jsbb1,
                        sfdz = sfdz1,
                        jhfs = jsfs1,
                        khmc = khmc1,
                        sktj = sktj1,
                        jsfs = jsfs1,
                        cgy = cgy1,
                        cys = cys1,
                        ysdh = ysdh1

                    };


                    //操作人员信息
                    operationinfo operationinfo1 = new operationinfo()
                    {
                        operatorAbAb = UserAccount,
                        operationDate = DateTime.Now.ToString("yyyy-MM-dd"),
                        operationTime = DateTime.Now.ToString("HH:mm:ss")
                    };

                    String currentTimeTamp = getTimestamp();
                    String md5Source = httpSystemId + httpPassword + currentTimeTamp;
                    String md5OfStr = Md5(md5Source).ToLower();


                    Header header1 = new Header()
                    {
                        systemid = httpSystemId,
                        currentDateTime = currentTimeTamp,
                        Md5 = md5OfStr
                    };

                    Data data = new Data()
                    {
                        operationinfo = operationinfo1,
                        mainTable = mainTable1
                    };

                    List<Data> datas = new List<Data>();
                    datas.Add(data);


                    DataHeader dataHeader = new DataHeader()
                    {
                        data = datas,
                        header = header1
                    };
                    var json = JsonConvert.SerializeObject(dataHeader);
                    json = json.ToString().Replace("operatorAbAb", "operator");
                    #endregion

                    #region 查询赋值
                    ReceivableSelectModel.mainTable mainTable2 = new ReceivableSelectModel.mainTable()
                    {
                        djnm = FID
                    };
                    //操作人员信息
                    ReceivableSelectModel.operationinfo operationinfo2 = new ReceivableSelectModel.operationinfo()
                    {
                        operatorAbAb = UserAccount,

                    };
                    ReceivableSelectModel.Header header2 = new ReceivableSelectModel.Header()
                    {
                        systemid = httpSystemId,
                        currentDateTime = currentTimeTamp,
                        Md5 = md5OfStr
                    };
                    ReceivableSelectModel.DataHeader dataHeader1 = new ReceivableSelectModel.DataHeader()
                    {
                        operationinfo = operationinfo2,
                        mainTable = mainTable2,
                        header = header2
                    };

                    var jsonS = JsonConvert.SerializeObject(dataHeader1);
                    jsonS = jsonS.ToString().Replace("operatorAbAb", "operator");
                    #endregion

                    //查询是否存在
                    var httpJson = GlobalParameters.PostToPushGroupNews(httpUrl + "/cube/restful/interface/getDataByPK/select_bill", jsonS);

                    var arrresult = JsonConvert.DeserializeObject<SortedDictionary<string, object>>(httpJson);//转换
                    var MainTable = JsonConvert.DeserializeObject<SortedDictionary<string, object>>(arrresult["result"].ToString());//转换


                    if (MainTable.Count == 0)//
                    {

                        var AddJson = GlobalParameters.PostToPushGroupNews(httpUrl + "/cube/restful/interface/saveOrUpdateModeData/create_bill", json);

                        var Addresult = JsonConvert.DeserializeObject<GlobalParameters.ReturnJson>(AddJson);//转换


                        if (Addresult.status == "1")
                        {
                            #region 应收单写日志(插入一张CRM接口日志单据，更新单据上的接口调用方式/调用时间/调用结果）
                            Common.InterfaceLog interfaceLog = new Common.InterfaceLog();
                            interfaceLog.FBILLNO = Number;
                            interfaceLog.FBILLID = FID;
                            interfaceLog.FDATE = System.DateTime.Now;
                            interfaceLog.FINTERNAME = " 应收单";
                            interfaceLog.FInvokeType = " 应收单新增";
                            interfaceLog.Ftoken = "";
                            interfaceLog.FSTATUS = "成功";
                            interfaceLog.FRequsetData = json.ToString();
                            interfaceLog.FReturnData = AddJson.ToString();
                            interfaceLog.FRequest = json.ToString();
                            interfaceLog.FReturn = AddJson.ToString();
                            string LogSql = interfaceLog.WriteCRMLogSql();//获取写入日志单据的SQL
                            List<string> sqlList = new List<string>();
                            if (!string.IsNullOrEmpty(LogSql))
                            {
                                sqlList.Add(LogSql);
                            }
                            //更新单据
                            string updateSql = string.Format(@"/*dialect*/ update t_AR_receivable set F_DEV_FDATE='{0}',F_DEV_FSTATUS='{1}' 
                    where FID={2}", interfaceLog.FDATE, interfaceLog.FSTATUS, FID);
                            sqlList.Add(updateSql);
                            DBServiceHelper.ExecuteBatch(this.Context, sqlList);
                            IOperationResult operationResult = new OperationResult();

                            operationResult.OperateResult.Add(new OperateResult()
                            {
                                SuccessStatus = true,
                                Message = string.Format("应收单数据上传成功！"),
                                MessageType = MessageType.Warning,
                                PKValue = 0,
                            });
                            this.OperationResult.MergeResult(operationResult);

                            #endregion
                        }
                        else
                        {
                            #region 应收单写日志(插入一张CRM接口日志单据，更新单据上的接口调用方式/调用时间/调用结果）
                            Common.InterfaceLog interfaceLog = new Common.InterfaceLog();
                            interfaceLog.FBILLNO = Number;
                            interfaceLog.FBILLID = FID;
                            interfaceLog.FDATE = System.DateTime.Now;
                            interfaceLog.FINTERNAME = "应收单";
                            interfaceLog.FInvokeType = "应收单新增";
                            interfaceLog.Ftoken = "";
                            interfaceLog.FSTATUS = "失败";
                            interfaceLog.FRequsetData = json.ToString();
                            interfaceLog.FReturnData = AddJson.ToString();
                            interfaceLog.FRequest = json.ToString();
                            interfaceLog.FReturn = AddJson.ToString();
                            string LogSql = interfaceLog.WriteCRMLogSql();//获取写入日志单据的SQL
                            List<string> sqlList = new List<string>();
                            if (!string.IsNullOrEmpty(LogSql))
                            {
                                sqlList.Add(LogSql);
                            }
                            //更新单据
                            string updateSql = string.Format(@"/*dialect*/ update t_AR_receivable set F_DEV_FDATE='{0}',F_DEV_FSTATUS='{1}' 
                    where FID={2}", interfaceLog.FDATE, interfaceLog.FSTATUS, FID);
                            sqlList.Add(updateSql);

                            DBServiceHelper.ExecuteBatch(this.Context, sqlList);
                            IOperationResult operationResult = new OperationResult();

                            operationResult.OperateResult.Add(new OperateResult()
                            {
                                SuccessStatus = false,
                                Message = string.Format("应收单数据上传失败，请手工同步！"),
                                MessageType = MessageType.Warning,
                                PKValue = 0,
                            });
                            this.OperationResult.MergeResult(operationResult);


                            #endregion
                        }

                    }
                    else
                    {
                        //cube / restful /interface/saveOrUpdateModeData/update_Transportation_area
                        var UpdateJson = GlobalParameters.PostToPushGroupNews(httpUrl + "/cube/restful/interface/saveOrUpdateModeData/update_bill", json);

                        var Updateresult = JsonConvert.DeserializeObject<GlobalParameters.ReturnJson>(UpdateJson);//转换

                        if (Updateresult.status == "1")
                        {
                            #region 收款单写日志(插入一张CRM接口日志单据，更新单据上的接口调用方式/调用时间/调用结果）
                            Common.InterfaceLog interfaceLog = new Common.InterfaceLog();
                            interfaceLog.FBILLNO = Number;
                            interfaceLog.FBILLID = FID;
                            interfaceLog.FDATE = System.DateTime.Now;
                            interfaceLog.FINTERNAME = "应收单";
                            interfaceLog.FInvokeType = "应收单更新";
                            interfaceLog.Ftoken = "";
                            interfaceLog.FSTATUS = "成功";
                            interfaceLog.FRequsetData = json.ToString();
                            interfaceLog.FReturnData = UpdateJson.ToString();
                            interfaceLog.FRequest = json.ToString();
                            interfaceLog.FReturn = UpdateJson.ToString();
                            string LogSql = interfaceLog.WriteCRMLogSql();//获取写入日志单据的SQL
                            List<string> sqlList = new List<string>();
                            if (!string.IsNullOrEmpty(LogSql))
                            {
                                sqlList.Add(LogSql);
                            }
                            //更新单据
                            string updateSql = string.Format(@"/*dialect*/ update t_AR_receivable set F_DEV_FDATE='{0}',F_DEV_FSTATUS='{1}' 
                    where FID={2}", interfaceLog.FDATE, interfaceLog.FSTATUS, FID);
                            sqlList.Add(updateSql);
                            DBServiceHelper.ExecuteBatch(this.Context, sqlList);

                            #endregion
                        }
                        else
                        {
                            #region 收款单写日志(插入一张CRM接口日志单据，更新单据上的接口调用方式/调用时间/调用结果）
                            Common.InterfaceLog interfaceLog = new Common.InterfaceLog();
                            interfaceLog.FBILLNO = Number;
                            interfaceLog.FBILLID = FID;
                            interfaceLog.FDATE = System.DateTime.Now;
                            interfaceLog.FINTERNAME = "应收单";
                            interfaceLog.FInvokeType = "应收单更新";
                            interfaceLog.Ftoken = "";
                            interfaceLog.FSTATUS = "失败";
                            interfaceLog.FRequsetData = json.ToString();
                            interfaceLog.FReturnData = UpdateJson.ToString();
                            interfaceLog.FRequest = json.ToString();
                            interfaceLog.FReturn = UpdateJson.ToString();
                            string LogSql = interfaceLog.WriteCRMLogSql();//获取写入日志单据的SQL
                            List<string> sqlList = new List<string>();
                            if (!string.IsNullOrEmpty(LogSql))
                            {
                                sqlList.Add(LogSql);
                            }
                            //更新单据
                            string updateSql = string.Format(@"/*dialect*/ update t_AR_receivable set F_DEV_FDATE='{0}',F_DEV_FSTATUS='{1}' 
                    where FID={2}", interfaceLog.FDATE, interfaceLog.FSTATUS, FID);

                            sqlList.Add(updateSql);

                            DBServiceHelper.ExecuteBatch(this.Context, sqlList);
                            #endregion
                        }

                    }
                }
            }
        }
        /// <summary>
        /// api配置
        /// </summary>
        public DataTable APISetting()
        {
            string Sql = string.Format(@"select * from RDLV_t_CRMInterface");
            return DBServiceHelper.ExecuteDataSet(this.Context, Sql).Tables[0];

        }

        /// <summary>
        /// md5加密
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public static String Md5(string s)
        {
            char[] hexDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
            MD5 md5 = new MD5CryptoServiceProvider();
            byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(s);
            byte[] result = md5.ComputeHash(inputBytes);
            int j = result.Length;
            char[] str = new char[j * 2];
            int k = 0;
            for (int i = 0; i < j; i++)
            {
                byte byte0 = result[i];
                str[k++] = hexDigits[byte0 >> 4 & 0xf];
                str[k++] = hexDigits[byte0 & 0xf];
            }
            return new String(str);
        }
        /**
       * 获取时间戳   格式如：19990101235959
       * @return
       */
        public static String getTimestamp()
        {

            return DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("-", "").Replace(":", "").Replace(" ", "").Replace("/", "");
        }


    }
}
